<?php
	require('connect.php');
	if ($_REQUEST['tim']) {
		$tim = 	$_REQUEST['tim'];
		$nam = date("Y");
		if (strpos(" ".$tim,"_T") == 1) {
			$tim = ltrim($tim,"_");
			$result = $mysqli->query("select tre.MA_TRE,HOTEN_TRE,TEN_LOP,HOTEN_PH FROM tre,hoc,lop,phuhuynh where
										tre.MA_TRE = hoc.MA_TRE and
										tre.MA_PH = phuhuynh.MA_PH and
										hoc.MA_LOP = lop.MA_LOP and
										hoc.NAMHOC = {$nam} and
										tre.MA_TRE = '{$tim}'")
			or die($mysqli->error);
		} else
			$result = $mysqli->query("select tre.MA_TRE,HOTEN_TRE,TEN_LOP,HOTEN_PH FROM tre,hoc,lop,phuhuynh where
										tre.MA_TRE = hoc.MA_TRE and
										tre.MA_PH = phuhuynh.MA_PH and
										hoc.MA_LOP = lop.MA_LOP and
										hoc.NAMHOC = {$nam} and
										tre.HOTEN_TRE = '{$tim}'");
		if ($result->num_rows == 0) {
			echo "<p>Không tìm thấy kết quả</p>";
		} else {
			echo "<table border='1' id='danhsach'>";
			echo "<tr><th>MÃ TRẺ</th><th>HỌ TÊN TRẺ</th><th>TÊN LỚP</th><th>HỌ TÊN PHỤ HUYNH</th><th>TÙY CHỌN</th></tr>";
            while ($row=$result->fetch_array()) {
				echo "<tr><td>{$row['MA_TRE']}</td><td>{$row['HOTEN_TRE']}</td><td>{$row['TEN_LOP']}</td>
					<td>{$row['HOTEN_PH']}</td><td id='nut' style='text-align:center'>";?>
					<input type='button' value='Xem chi tiết' onClick="xemchitiet('<?php echo $row['MA_TRE']; ?>')" />
					<input type='button' value='Xóa' onClick="xoa('<?php echo $row['MA_TRE'] ?>')" /></td></tr><?php
            }
			echo "</table>";
		}
	}
?>